﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TabbedTemplate.Models;

namespace TabbedTemplate.Services
{
    public class DataService : IDataService
    {
        private ICityLocationsService _cityLocationsService;

        public DataService(ICityLocationsService cityLocationsService)
        {
            _cityLocationsService = cityLocationsService;
        }


        public async Task<List<string>> GetCitySearchResult(string query)
        {

            if (!_cityLocationsService.CityListInitilized())
            {
                await _cityLocationsService.InitializeCityListAsync();
            }

            IList<City> cities =
                await _cityLocationsService.SearchCityAsync(query);

            List<string> res = cities.Select(p => p.CityName).ToList();

            return res;
        }
    }
}
